package com.example.onlineanswer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.onlineanswer.model.entity.Participation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 参赛记录Mapper接口
 */
@Mapper
public interface ParticipationMapper extends BaseMapper<Participation> {

    /**
     * 检查用户是否已参加竞赛
     *
     * @param contestId 竞赛ID
     * @param userId 用户ID
     * @return 参赛记录ID，不存在则返回null
     */
    @Select("SELECT id FROM participation " +
            "WHERE contest_id = #{contestId} AND user_id = #{userId} " +
            "AND status = 1 AND is_deleted = 0 " +
            "LIMIT 1")
    Long checkUserParticipation(@Param("contestId") Long contestId, @Param("userId") Long userId);
} 